﻿#ifndef DATAANALYSISWINDOW_H
#define DATAANALYSISWINDOW_H

#include <QWidget>
#include <QChartView>
#include <QShowEvent>
#include <QObject>
#include <qvalueaxis.h>
#include <qsplineseries.h>
#include <qlineseries.h>
#include <qtimer.h>
#include <QRandomGenerator>
#include <QTime>
#include <QBarSet>
#include <QBarSeries>
#include <QBarCategoryAxis>
#include <dbHelper.h>
#include <mainwindow.h>
#include <QTimer>
#include <QDebug>
#include <QtMath>
#include <QtCharts>
#include <QLineSeries>
#include <analyse.h>
#include <QLibrary>
#include <QBarSet>
#include <QBarSeries>
#include <QBarCategoryAxis>
#include <dbHelper.h>
#include <QMouseEvent>
#include <QDomDocument>
#include <dataAnalysisThread.h>
#include <dataAnalsisByJThread.h>
#include "fxpz.h"
#include "ui_fxpz.h"
#include "anscr.h"
#include "ui_anscr.h"
#include "ui_alert.h"
#include <tcts.h>
#include "ui_tcts.h"

using namespace QtCharts;//不要忘记添加这一行

namespace Ui {
class DataAnalysisWindow;
}

class DataAnalysisWindow : public QWidget
{
public:
    Q_OBJECT

public:
    explicit DataAnalysisWindow(QWidget *parent = nullptr);
    ~DataAnalysisWindow();
    void refOriginalCurveTable();
    void refAmplificationCurveTable();
    void standardCurveChart(); // 标准曲线初始化
    void guide();// 指导建议
    void datao();//表格导出

signals:
    void changeMainWindow();
    void changeExperiInfoWindow();
    void changeSampleWindow();
    void pointLabelsVisibilityChanged(bool visible);

private slots:

    void on_comboBox_currentTextChanged(const QString &arg1);

    void on_FAMCheckBox_clicked();

    void on_VICCheckBox_clicked();

    void on_ROXCheckBox_clicked();

    void on_CY5CheckBox_clicked();

    void on_checkBox_3_stateChanged(int arg1);

    void on_checkBox_2_stateChanged(int arg1);

    void on_checkBox_stateChanged(int arg1);

    void on_pushButton_4_clicked();

    void on_FAMCheckBox_clicked(bool checked);

    void on_VICCheckBox_clicked(bool checked);

    void on_ROXCheckBox_clicked(bool checked);

    void on_CY5CheckBox_clicked(bool checked);

    void on_clicked_leftmouse1(int flag);// 筛选槽函数
    void on_pushButton_clicked();

    void on_pushButton_6_clicked();
    void on_pushButton_9_clicked();
    void on_pushButton_10_clicked();

    void on_lineEdit_editingFinished();

    void on_lineEdit_2_editingFinished();

    void on_lineEdit_3_editingFinished();

    void on_lineEdit_4_editingFinished();

    void on_tableWidget_itemSelectionChanged();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_7_clicked();

    void on_pushButton_8_clicked();

    void on_pushButton_11_clicked();

    void on_pushButton_12_clicked();

    void on_pushButton_13_clicked();

    void on_pushButton_14_clicked();
    void on_checkBox_4_stateChanged(int arg1);


    void on_pushButton_15_clicked();


    void on_pushButton_16_clicked();

    void refl();
private:
    void showEvent(QShowEvent *event) override;
    void refOriginalCurveChart();
    void refAmplificationCurveChart();
    void refCtValue(QString,double);

    void drawThresholdLine();
    void drawRelaThresholdLine(QString);

    void drawNormalChart();
    void drawRnChart();
    void drawLogChart();
    QString getChartQuerySql(QString,QString);
    QString GetChartQueryPosition();

private:
    Ui::DataAnalysisWindow *ui;
    QChart* myChart;
    dbHelper* dbClient;
    Analyse *analyseClient;
    DataAnalysisThread *dataAnaly;
    fxpz *fxpzui;
    anscr *anscrui;
    tcts *tcts1;
    QLineSeries* thresholdLine;
    QValueAxis * axisY;
    QValueAxis * axisX;
    QLineSeries *fThresholdLine;
    QLineSeries *rThresholdLine;
    QLineSeries *vThresholdLine;
    QLineSeries *cThresholdLine;
    QString defaultAccess;

    QVector<QSplineSeries*> allOrigLines;
    QVector<QSplineSeries*> allAmplLines;
    QVector<QSplineSeries*> allRnLines;
    QVector<QSplineSeries*> allLogLines;
    QVector<QSplineSeries*> allNormalLines;

    QValueAxis *m_axisX, *m_axisY;// 横纵坐标轴对象
    void calculateLinearRegression(const QVector<double>& x, const QVector<double>& y, double& k, double& b, double& rSquared,double& cubeRoot);// 标准曲线计算
    QLineSeries *bzROX,*bzVIC,*bzFAM,*bzCY5;// 标准曲线
    QScatterSeries *bzsdROX,*bzsdVIC,*bzsdFAM,*bzsdCY5,*fbzROX,*fbzVIC,*fbzFAM,*fbzCY5;// 标准曲线散点
    QVector<double> logvalue(QVector<double> valuelog);// 取log
    int maxCircleNum=0;
    double normalizeData[100];
    bool refWindow;

    QStringList mwnd(double valnVIC,double valnFAM);// 男性浓度，女性浓度，男女浓度比例计算
    QStringList zsjs(double valnVIC,double valnROX,double valnCY5C,double valCJ);// 抑制指数，降解指数计算
    QStringList gui(double valnROX,double valnVIC,double valnFAM,double valnCY5C,double valCJ); // 指导建议及稀释/扩增方案
    void numlu();//总数等值计算初始化

    QStringList qut;// 浓度平均值
    double krox, brox, r2rox, curox, kvic, bvic, r2vic, cuvic, kfam, bfam, r2fam, cufam, kcy5, bcy5, r2cy5, cucy5;// 斜率等
    int vsfl1=0,vsfl2=0;
    int doutfl=0;
    QString outpath;
    QMap<QString,double> CQMeanF,CQMeanV,CQMeanR,CQMeanC;
    QMap<QString,QList<double>> CQvalreF,CQvalreV,CQvalreR,CQvalreC;
    QMap<QString,double> CQSTDF,CQSTDV,CQSTDR,CQSTDC;
    double Mean(QList<double> CQval);
    double STD(QList<double> CQval);
    int bzsum=0;
    bool isYing;
    int xhval=0;
    bool famcb,viccb,roxcb,cy5cb;
    QString fileName;
    QString fileName2;
    QString fileName3;
};
#endif // DATAANALYSISWINDOW_H
